﻿using SXT.Party.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace ZHDJ.MobileInterface
{
    /// <summary>
    /// MobileInterfaceService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [System.Web.Script.Services.ScriptService]
    public class MobileInterfaceService : System.Web.Services.WebService
    {
        [WebMethod]
        public string PushInformation(string id, string publishTime, string source, string title, string type)
        {
            string logMsg = "";
            string paramStr = "";
            string resultStr = "";
            PushInformationInParam inparam = new PushInformationInParam();
            try
            {
                InterfaceHelper.SendInfoDaoyi(id, publishTime, source, title, type);
            }
            catch (Exception ex)
            {
                logMsg = ex.Message + ":" + ex.StackTrace;
                resultStr = ""; ;
            }

            return resultStr;
        }

        /// <summary>
        /// 短信发送
        /// </summary>
        /// <param name="conten">短信内容，不能超过1024个字符</param>
        /// <param name="mobiles">手机号码，多个手机号码以小写逗号分隔</param>
        /// <param name="validate">验证码（由接口提供）</param>
        /// <returns></returns>
        [WebMethod]
        public string SMSSend(string conten, string mobiles, string validate)
        {
            if (validate != System.Configuration.ConfigurationManager.AppSettings["MoSms.Validate"])
            { return ""; }

            List<string> lstMobile = new List<string>();
            List<string> ErrorListMobile = new List<string>();

            string[] mobileArray = mobiles.Split(',');

            foreach (string item in mobileArray)
            {
                //判断是否是手机号码
                if (item.Length == 11 && item[0].ToString() == "1")
                {
                    lstMobile.Add(item);
                }
                else
                {
                    ErrorListMobile.Add(item);
                }
            }
            if (ErrorListMobile.Count > 0)
            {
                SXT.Party.Utility.PartyMOSms.insertErrorMobileNo(string.Join(",", ErrorListMobile.ToArray()), "");
            }
            string Result = PartyMOSms.SmsSend(conten, lstMobile, "SXT.DefaultDBEx");
            return Result;
        }

        /// <summary>
        /// 短信发送  掌上组织生活
        /// </summary>
        /// <param name="conten">短信内容，不能超过1024个字符</param>
        /// <param name="mobiles">手机号码，多个手机号码以小写逗号分隔</param>
        /// <param name="validate">验证码（由接口提供）</param>
        /// <returns></returns>
        [WebMethod]
        public string SMSSendPocket(string conten, string mobiles, string validate, string IsPocketMeeting = "")
        {
            if (validate != System.Configuration.ConfigurationManager.AppSettings["MoSms.Validate"])
            { return ""; }

            List<string> lstMobile = new List<string>();
            List<string> ErrorListMobile = new List<string>();

            string[] mobileArray = mobiles.Split(',');

            foreach (string item in mobileArray)
            {
                //判断是否是手机号码
                if (item.Length == 11 && item[0].ToString() == "1")
                {
                    lstMobile.Add(item);
                }
                else
                {
                    ErrorListMobile.Add(item);
                }
            }
            if (ErrorListMobile.Count > 0)
            {
                SXT.Party.Utility.PartyMOSms.insertErrorMobileNo(string.Join(",", ErrorListMobile.ToArray()), "");
            }
            string Result = PartyMOSms.SmsSend(conten, lstMobile, "SXT.DefaultDBEx", IsPocketMeeting: IsPocketMeeting);
            return Result;
        }
    }
}
